package cn.looov.demo.future.service;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class FutureService {

	public List<Future<Integer>> test1(List<Integer> nums){
		
		List<Future<Integer>> list = new ArrayList<Future<Integer>>(nums.size());
		nums.forEach(item->{
			list.add(calculate(item));
		});
		return list;
	}
	public Future<Integer> calculate(Integer input) {
		
		ExecutorService executor = Executors.newSingleThreadExecutor();
		
		
		
		
		return executor.submit(() -> {
			System.out.println("Calculating11..." + input);
			Thread.sleep(5000);
			
			return input * input;
		});
	}

}
